<?php


namespace App\Models\Field;

class BaseField
{
    public const BASE_INFO = 'baseInfo';
    public const SELF_LIST = 'selfList';
    public const SELF_DETAIL = 'selfDetail';

    public static function format($model, $formats)
    {
        $arr = [];
        foreach ($formats as $key => $value) {
            if (is_string($key)) {
                if ($value instanceof \Closure) {
                    $arr[$key] = call_user_func($value, $model);
                } else {
                    $arr[$key] = $value;
                }
            } else {
                $arr[$value] = $model[$value];
            }
        }
        return $arr;
    }
}
